package com.example.juc;

import com.example.multithread.MyThread;

import java.util.concurrent.ThreadFactory;

class MyThreadFactory implements ThreadFactory {
    private static final ThreadFactory INSTANCE = new MyThreadFactory();
    private static final String TITLE = "thread-";
    private static int count = 0;
    private MyThreadFactory(){}
    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, TITLE + count++);
    }
    public static ThreadFactory getInstance() {
        return INSTANCE;
    }
}
public class ThreadFactoryTest {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = MyThreadFactory.getInstance().newThread(() -> {
                System.out.println("多线程执行: " + Thread.currentThread().getName());
            });
            thread.start();
        }
    }
}
